﻿@page
@model Emprise.Web.Pages.User.RegModel
@{
    ViewData["Title"] = "注册";
}
@{
    Layout = "_Layout";
}

    <div class="big_bg" id="app">
        <div class="nav">
            <h2 class="nav-title">注册</h2>
            <a href="@(Url.Page("/User/Login"))" class="nav-back"><span><<返回</span></a>
        </div>

        <div class="main">
            <div>
                <div class="login-nonreg">
                    <form>

                        <div class="form-text-login">
                            <label>用户名：</label>
                            <input type="text" class="form-text" v-model="email" readonly="readonly" />
                            <a href="javascript:;" class="form-text-clear fn-hide"><i class="icon icon-clear"></i></a>
                        </div>
                        @if (Model.IsNeedEmail)
                        {
                            <div class="form-text-login">
                                <label>邮箱：</label>
                                <input type="text" class="form-text" v-model="email" readonly="readonly" />
                                <a href="javascript:;" class="form-text-clear fn-hide"><i class="icon icon-clear"></i></a>
                            </div>
                        }


                        <div class="form-text-login">
                            <label>密码：</label>
                            <input type="password" class="form-text" v-model="password" />
                            <a href="javascript:;" class="form-text-clear" v-show="password" v-on:click="password=''"><i class="icon icon-clear"></i></a>
                        </div>

                        <div class="form-text-login">
                            <label>重复：</label>
                            <input type="password" class="form-text" v-model="password2" />
                            <a href="javascript:;" class="form-text-clear" v-show="password2" v-on:click="password2=''"><i class="icon icon-clear"></i></a>
                        </div>
                    </form>

                </div>
                <div class="fn-mt-login fn-mlr">
                    <a class="btn btn-bar-tawny" href="javascript:;" v-on:click="reg"> 确 定 </a>
                </div>
                <div class="fn-mt-login fn-mlr" style="text-align:right;">
                    <a style="font-size:12px;" href="@(Url.Page("/User/Login"))">已有账号，直接登录</a>
                </div>
                <div class="fn-mt fn-mlr"><span class="tip01 tips">{{tips}}</span></div>
            </div>

        </div>

        @await Html.PartialAsync("_Footer", Model.SiteConfig)

        <div class="loading" v-show="loading">
            <img src="/images/loading.gif">
        </div>
    </div>
@section Scripts {
    <script type="text/javascript">
        var vm = new Vue({
            el: '#app',
            data: {
                email: "@(Model.Email)",
                password: "",
                password2: "",
                code:"@(Model.Code)",
                tips: "",
                loading: 0
            },
            methods: {
                reg: function () {
                    var that = this;
                    that.tips = "";

                    if (!that.email || !that.password || !that.password2) {
                        that.tips = "请输入邮箱和密码";
                        return false;
                    }

                    if (that.password!=that.password2) {
                        that.tips = "两次密码不一致";
                        return false;
                    }

                    that.loading = 1;

                    axios.post("/api/user/reg", {
                        email: that.email,
                        password: that.password,
                        code:that.code
                    })
                    .then(function (response) {
                        var result = response.data;
                        if (result.status) {
                            location.href = "@(Url.Page("/User/Index"))";
                        } else {
                            var error = result.errorMessage || "登录失败";
                            if (result.data) {
                                error += "<br>" + result.data;
                            }
                            that.tips = error;
                        }
                        that.loading = 0;
                    })
                    .catch(function (error) {
                        console.log(error);
                        that.loading = 0;
                    });
                }
            }
        });
     @*
    ({
        reg: function () {
            $("#msgTip").html("");

            if (!$("input[name=email]").val()) {
                return false;
            }
            if (!$("input[name=password]").val()) {
                return false;
            }
            if (!$("input[name=password2]").val()) {
                return false;
            }

            if ($("input[name=password]").val() != $("input[name=password2]").val()) {
                $("#msgTip").html("两次密码必须一致");
                return false;
            }


            var index = layer.load(2);

            $.ajax({
                type: "POST",
                url: "/api/user/reg",
                data: $("form").serialize(),
                success: function (result) {
                    if (result.status) {
                        location.href = "@(Url.Page("/User/Index"))";
                    } else {
                        var error = result.errorMessage||"注册失败";
                        if (result.data) {
                            error += "<br>" + result.data;
                        }
                        $("#msgTip").html(error);
                    }
                    layer.close(index);
                }, error: function () {
                    layer.close(index);
                }
            });
        },
        init : function () {
            var that = this;

            $(function () {
                layer.config({
                    skin: 'layui-layer-hei'
                });

                $(document).on("click", "#formReg", function () {
                    that.reg();
                });

                $(document).on("keyup", "input", function () {
                    var obj = $(this);
                    if (obj.val()) {
                        obj.next("a").show();
                    } else {
                        obj.next("a").hide();
                    }
                });

                $(document).on("click", ".form-text-clear", function () {
                    var obj = $(this);
                    obj.prev("input").val("");
                    obj.hide();
                });
            });



        }
    }).init();*@
    </script>
}

